package com.example.gray.controller;


import com.example.gray.entity.User;
import com.example.gray.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Lord
 * @date 2021/12/27 14:49
 */
@RestController
@RequestMapping(value = "/user")
@Api(tags = "用户")
public class HelloWorld {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "查找用户")
    @GetMapping(value = "search")
    public String search(String name){
        User user = userService.getUser(name);
        return user.toString();
    }

    @ApiOperation(value = "插入用户")
    @PostMapping(value = "insert")
    public String insert(String name,String password){
        User user = new User(1,name,password,1);
        return "插入结果："+userService.insertUser(user);
    }

    @ApiOperation(value = "删除用户")
    @PostMapping(value = "delete")
    public String delete(Integer id){
        return "删除结果："+userService.deleteUser(id);
    }

}
